defmodule CheckUtil do
	@moduledoc false

	require ProjectType

	def uids_valid?([]) do
		false
	end
	def uids_valid?(list) when is_list(list) do
		list
		|> Enum.all?(
			   fn (h) ->
				   uid_valid?(h)
			   end
		   )
	end
	def uids_valid?(_) do
		false
	end

	def is_digital?(list) when is_list(list) do
		Enum.all?(list, &is_digital?(&1))
	end
	def is_digital?(v) do
		is_integer(v) || is_float(v)
	end


	def ele_is_binary?([]) do
		true
	end

	def ele_is_binary?(list) do
		list
		|> Enum.all?(
			   fn (name) ->
				   name_valid?(name)
			   end
		   )
	end


	def eq_gt0?(num) do
		is_integer(num) && num >= 0
	end


	def unit_valid?(_unit) do
		true
	end

	def date_valid?(date) do
		NaiveDateTime.from_iso8601(date)
		|> case do
			   {:ok, _} ->
				   true
			   _ ->
				   false
		   end
	end

	def star_valid?(star) do
		is_integer(star) && star > 0 && star < 6
	end

	def str_valid?("") do
		true
	end
	def str_valid?(base) when is_binary(base) do
		true
	end
	def str_valid?(_) do
		false
	end

	def not_empty_str?(nil) do
		false
	end
	def not_empty_str?(list) when is_list(list) do
		Enum.all?(
			list,
			fn (str) ->
				not_empty_str?(str)
			end
		)
	end
	def not_empty_str?(str) do
		is_binary(str) && String.length(str) > 0
	end

	def proj_valid(proj_type) do
		Enum.member?(ProjectType.all_proj(), proj_type)
	end


	def uid_valid?("") do
		false
	end
	def uid_valid?(uid) when is_binary(uid) do
		!String.contains?(uid, "'")
	end
	def uid_valid?(_) do
		false
	end




	def page_valid?(page) do
		is_integer(page) && page > 0 && page < 9999
	end

	def phone_valid?(_) do
		true
	end

	def name_valid?(name) when is_binary(name) do
		String.length(name) != 0
	end
	def name_valid?(_) do
		false
	end

	def list_valid?(list) when Kernel.is_list(list) do
		true
	end
	def list_valid?(_) do
		false
	end
	def passwd_valid?(passwd) do
		String.length(passwd) >= 6
	end

	def is_bool?(val) do
		is_boolean(val)
	end


	def list_member_valid?(constant_list, check_list) do
		Enum.all?(
			check_list,
			fn (h) ->
				Enum.member?(constant_list, h)
			end
		)
	end

	def reg_type_valid?(type) do
		is_binary(type)
	end


end
